﻿/**********************************************************
 ●项目：Smartkernel
 ●公司：智能核心信息技术研发中心
 ●作者：曹艳白
 ●邮箱：caoyanbai@gmail.com
 ●创建：2008-08-10
**********************************************************/
using System;
using System.Diagnostics;

namespace Smartkernel.IO
{
    /// <summary>
    /// Rar格式压缩解压：提供对Rar格式压缩解压操作
    /// </summary>
    public static class SmartRar
    {
        /// <summary>
        /// 压缩文件
        /// </summary>
        /// <param name="winRarAppPath">WinRar程序路径，例如：C:\Program Files\WinRAR\WinRAR.exe</param>
        /// <param name="sourcePath">源文件路径，可以是文件，也可以是文件夹，注意，路径中不能有空格</param>
        /// <param name="targetPath">目标路径</param>
        /// <param name="password">压缩的密码</param>
        public static void Compress(string winRarAppPath, string sourcePath, string targetPath, string password)
        {
            string args = args = String.Format("a -r -ibck -inul -p{0} {1} {2}", password, targetPath, sourcePath);
            SmartProcess.Start(winRarAppPath, ProcessWindowStyle.Hidden, args);
        }
        /// <summary>
        /// 压缩文件
        /// </summary>
        /// <param name="winRarAppPath">WinRar程序路径，例如：C:\Program Files\WinRAR\WinRAR.exe</param>
        /// <param name="sourcePath">源文件路径，可以是文件，也可以是文件夹，注意，路径中不能有空格</param>
        /// <param name="targetPath">目标路径</param>
        public static void Compress(string winRarAppPath, string sourcePath, string targetPath)
        {
            string args = args = String.Format("a -r -ibck -inul {0} {1}", targetPath, sourcePath);
            SmartProcess.Start(winRarAppPath, ProcessWindowStyle.Hidden, args);
        }
        /// <summary>
        /// 解压缩文件
        /// </summary>
        /// <param name="winRarAppPath">WinRar程序路径，例如：C:\Program Files\WinRAR\WinRAR.exe</param>
        /// <param name="sourcePath">待解压的文件路径</param>
        /// <param name="targetPath">目标路径，文件夹名，只能是文件集名，不能是文件名</param>
        /// <param name="password">解压的密码</param>
        public static void Decompress(string winRarAppPath, string sourcePath, string targetPath, string password)
        {
            string args = String.Format("x -o+ -ibck -inul -ep -p{0} {1} {2}", password, sourcePath, targetPath);
            SmartProcess.Start(winRarAppPath, ProcessWindowStyle.Hidden, args);
        }
        /// <summary>
        /// 解压缩文件
        /// </summary>
        /// <param name="winRarAppPath">WinRar程序路径，例如：C:\Program Files\WinRAR\WinRAR.exe</param>
        /// <param name="sourcePath">待解压的文件路径</param>
        /// <param name="targetPath">目标路径，文件夹名，只能是文件集名，不能是文件名</param>
        public static void Decompress(string winRarAppPath, string sourcePath, string targetPath)
        {
            string args = String.Format("x -o+ -ibck -inul -ep {0} {1}", sourcePath, targetPath);
            SmartProcess.Start(winRarAppPath, ProcessWindowStyle.Hidden, args);
        }
    }
}
